home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / c / rel_sun4.c < prev    next >
C/C++ Source or Header  |  1989-10-26  |  4KB  |  168 lines

  1.  
  2. /* Copyright William Schelter. All rights reserved.  This file does
  3. the low level relocation which tends to be very system dependent.
  4. It is included by the file sfasl.c
  5. Thanks to Blewett@research.att.com, for an initial effort on this.
  6. */
  7.  
  8. /*
  9.    Unfortunately the original documentation of the relocation types
  10. was rather sketchy, so I was not able to determine the correct
  11. behaviour of types which were not currently being output.
  12.    
  13.   These will have to be added later, for the moment an abort will occur.
  14. One way to check your work is to compile sfasl.c defining STAND, and then
  15. compare (using comp.c) the output from it with the output from ld.
  16.   */
  17.  
  18. relocate()
  19. {
  20.   char *where;
  21.   {
  22.     unsigned int new_value;
  23.     long x;
  24.     where = the_start + relocation_info.r_address;
  25.     dprintf (where has %x , *where);
  26.     dprintf(   at %x -->, where );
  27. #ifdef DEBUG    
  28.     dshow();
  29. #endif    
  30.     if(relocation_info.r_extern)
  31.       {
  32.     switch (relocation_info.r_type)
  33.       {
  34.       case RELOC_DISP8:           /* Disp's (pc-rel)    */
  35.       case RELOC_DISP16:
  36.       case RELOC_DISP32:  abort();
  37.       case RELOC_WDISP30:
  38.         dprintf (          symbol_table[relocation_info.r_index].n_value %d,
  39.                        symbol_table[relocation_info.r_index].n_value);
  40.         new_value =
  41.           symbol_table[relocation_info.r_index].n_value
  42.         + relocation_info.r_addend
  43.           - (int)start_address;
  44.         break;
  45.       case RELOC_8:        /* simplest relocs    */
  46.       case RELOC_16:              
  47.       case RELOC_32:             
  48.       case RELOC_HI22:    /* SR 22-bit relocs   */ 
  49.       case RELOC_LO10:
  50.         dprintf(   symbol_table[relocation_info.r_index].n_value = %d ,
  51.                  symbol_table[relocation_info.r_index].n_value);
  52.         new_value =
  53.           symbol_table[relocation_info.r_index].n_value;
  54.  
  55.         break;
  56.       default:
  57.         printf ("extern non-supported relocation_info.r_type=%d\n",
  58.             relocation_info.r_type);
  59.         fflush (stdout);
  60.         goto DONT;
  61.       }
  62.     dprintf( new value %x , new_value);
  63.     dprintf( rtype %x , relocation_info.r_type);
  64.       }
  65.     else
  66.       {
  67.     switch(relocation_info.r_index)    /* was symbolnum */
  68.       {
  69.       case N_DATA: case N_BSS: case N_TEXT:
  70.         new_value= (int)start_address;
  71.         break;
  72.       default:
  73.         abort();
  74.         goto DONT;
  75.       }
  76.       }
  77.  
  78.     switch (relocation_info.r_type)
  79.       {
  80. #define WHERE relocation_info.r_addend
  81.       case RELOC_8:        /* simplest relocs    */
  82.     *(char *)where = x = new_value + WHERE;
  83.     break;
  84.       case RELOC_16:
  85.     *(short *)where = x = new_value + WHERE;
  86.     break;
  87.       case RELOC_32:
  88.     *(int *)where = x = new_value + WHERE;
  89.     break;
  90.  
  91.       case RELOC_DISP8:        /* Disp's (pc-rel)    */
  92.     abort();
  93.     *(char *)where = x = new_value + *(char *) where;
  94.     break;
  95.       case RELOC_DISP16:
  96.     abort();
  97.     *(short *)where = x = new_value + *(short *) where;
  98.     break;
  99.       case RELOC_DISP32:
  100.     abort();
  101.     *(int *)where = new_value + *(int *) where;
  102.     x =  new_value + *( int *) where;
  103.     break;
  104.  
  105.       case RELOC_WDISP30:    /* SR word disp's     */
  106. #define MASK30BITS 0x3FFFFFFF
  107.     *(int *)where = ((((int) new_value) >> 2) & MASK30BITS)
  108.       | (~MASK30BITS & ( *(int *) where));
  109.     break;
  110.  
  111.       case RELOC_WDISP22:
  112.     goto Default;
  113.  
  114.       case RELOC_HI22:        /* SR 22-bit relocs   */
  115.     x = ((unsigned long) (new_value + relocation_info.r_addend)) >> 10;
  116. #define MASK22 0x3fffff    
  117.     *(long *) where= (~MASK22 & *(long *)where) | x;
  118.     break;
  119.  
  120.       case RELOC_22:
  121.       case RELOC_13:        /* SR 13&10-bit relocs*/
  122.     goto Default;
  123.       case RELOC_LO10:
  124.     x = ((unsigned long) (new_value + relocation_info.r_addend)) & 0x3ff;
  125.     *(unsigned short *)(where + 2) |= x;
  126.     break;
  127.  
  128.       case RELOC_SFA_BASE:    /* SR S.F.A. relocs   */
  129.       case RELOC_SFA_OFF13:
  130.       case RELOC_BASE10:    /* base_relative pic */
  131.       case RELOC_BASE13:
  132.       case RELOC_BASE22:
  133.       case RELOC_PC10:        /* special pc-rel pic*/
  134.       case RELOC_PC22:
  135.       case RELOC_JMP_TBL:    /* jmp_tbl_rel in pic */
  136.       case RELOC_SEGOFF16:    /* ShLib offset-in-seg*/
  137.       case RELOC_GLOB_DAT:    /* rtld relocs */
  138.       case RELOC_JMP_SLOT:
  139.       case RELOC_RELATIVE:
  140.  
  141.       Default:
  142.       default:
  143.     printf ("non-supported relocation_info.r_type=%d\n",
  144.         relocation_info.r_type);
  145.     fflush (stdout);
  146.     abort();
  147.       }
  148.   DONT:;
  149.   }
  150.  
  151. }
  152.  
  153.  
  154. #ifdef DEBUG
  155.  
  156. dshow()
  157. { if(debug)
  158.   printf("\nrelocation_info:{r_address %d,r_index %d,r_extern %d \n r_type %d, r_addend %d"
  159.      , relocation_info.r_address
  160. , relocation_info.r_index
  161. , relocation_info.r_extern
  162. , relocation_info.r_type
  163. , relocation_info.r_addend);
  164.     fflush(stdout);}
  165.  
  166. #endif /* DEBUG */
  167.  
  168.